﻿<?php
$this->headTitle($this->translator('assignment_view_page_title'));

$this->headLink()
    ->appendStylesheet($this->APP_STATIC_SERVER.'/js/jquery.ui/themes/base/ui.core.css')
    ->appendStylesheet($this->APP_STATIC_SERVER.'/js/jquery.ui/themes/base/ui.resizable.css')
    ->appendStylesheet($this->APP_STATIC_SERVER.'/js/jquery.ui/themes/base/ui.dialog.css')
    ->appendStylesheet($this->APP_STATIC_SERVER.'/js/jquery.ui/themes/base/ui.theme.css');

$this->headScript()
    ->appendFile($this->APP_STATIC_SERVER.'/js/jquery.ui/ui.core.js')
    ->appendFile($this->APP_STATIC_SERVER.'/js/jquery.ui/ui.draggable.js')
    ->appendFile($this->APP_STATIC_SERVER.'/js/jquery.ui/ui.droppable.js')
    ->appendFile($this->APP_STATIC_SERVER.'/js/jquery.ui/ui.resizable.js')
    ->appendFile($this->APP_STATIC_SERVER.'/js/jquery.ui/ui.dialog.js');
?>
 
<style>
    .caption{
		font-weight: bold;
		background: #BCBBB9;
	}
	
	.box_account .grid_3{
		width: 250px;
		margin: 0;		
	}
	
	.box_account .grid_3:hover{
		background: #EFEDED;
	}
	
	.box_account .grid_3 label{
        display:block;
        float:left;
        height:26px;
        line-height:15px;
        margin-right:10px;
        width:80px;
    }  
    
    table{
		border-top:none;
		border-bottom:none;
	}
	.list table{
		width: 100%;
		border-top: 0px;
		border-bottom: 0px;
	}
	.list .caption td{
		font-weight: bold;
		background: #BCBBB9;
	}
	.list tr.caption:hover td{
		font-weight: bold;
		background: #BCBBB9;
	}
	.list tbody tr:hover td{
		background: #EFEDED;
	} 
    
    .evaluation_label{
    	display: block; 
    	float: left; 
    	line-height: 15px;
    	margin-right: 20px;
		width: 80px; 
    }
</style>

<?php if($this->no_exist):?>
    <div class="grid_12"><?php echo $this->translator('customer_no_exist');?></div>
<?php else:?>
<?php
    $user = $this->user;
    $customer = $this->customer;    
?>

<!--prestige-->
<div class="grid_12">
	<div class="grid_10 alpha">
        <div class="icon_title"><span><?php echo $this->user->full_name;?></span></div>
    </div>
    <div class="t_a_bottom"><hr style="padding:0;"/></div>
    <div class="grid_10 t_a_bottom">    	
        <div class="clearfix t_a_bottom">
        	<?php echo $this->translator('customer_evaluation');?>:
        	<?php if(@$this->avergePC->evaluation_counter):?>
            <b> <?php echo isset($this->avergePC->evaluation_point)?$this->avergePC->evaluation_point:0;?></b>(<?php echo $this->translator('customer_evaluation_point');?>) / <b><?php echo isset($this->avergePC->evaluation_counter)?$this->avergePC->evaluation_counter:0;?></b>(<?php echo $this->translator('customer_evaluation_counter');?>)
            <?php else:?>
            <?php echo $this->translator('account_not_feedback_yet');?>
            <?php endif;?>
        </div>        
    </div>    
</div>
<!--end prestige-->

<div class="grid_12">
	<!--Order list-->
	<div class="grid_9 alpha">
	    <?php if($this->isAllowAction):?>
	    <div class="icon_title"><span><?php echo $this->translator('customer_order_listing');?></span></div>	    
	    <?php if($this->numOrder <= 0):?>
	        <?php echo $this->translator('customer_order_not_found');?>
	    <?php else:?>
	    <table style="border:none; width: 100%" class="list">
	        <tr class="caption">
	            <td width="20%"><?php echo $this->translator('customer_order_invoice');?></td>
	            <td width="15%"><?php echo $this->translator('customer_order_shipping_price');?></td>
	            <td width="15%"><?php echo $this->translator('customer_order_subtotal');?></td>
	            <td width="25%"><?php echo $this->translator('customer_order_tracking');?></td>
	            <td width="20%"><?php echo $this->translator('customer_order_evaluation');?></td>	            
				<td width="5%">#</td>
	        </tr>
	        <?php
	            $orders = $this->orders
	        ?>
	        <?php foreach($orders as $order):?>
	        <?php
	            /**
	             * Tracking status
	            **/
	            $t_status = isset($this->arrStatus[$order->order_id])?$this->arrStatus[$order->order_id]:null;
	
	            /**
	             * Order currency
	            **/
	            $currency = ($order->order_modify_amount_currency)?$order->order_modify_amount_currency:$order->order_total_amount_currency;
	
	            $arrRouteView = array(
	                'user_name' => $this->user->user_name,
	                'order_id' => $order->order_id
	            );
	
	            /**
	             * Evaluation
	            **/
	            $evaluation = $this->arrEvalOrders[$order->order_id];
	        ?>
	        <tr>
	            <td>
	            	<a href="<?php echo $this->url($arrRouteView, 'customer_customer_view');?>" title="<?php echo $this->translator('customer_order_view_detail');?>"><?php echo $order->order_invoice;?></a><br>
	            	<font style="font-style: italic;"><?php echo date('d-m-Y', strtotime($order->order_created_date));?></font>
	            </td>
	            <td><?php echo $order->order_total_shipping_price;?>&nbsp;<?php echo $currency;?></td>
	            <td><?php echo ($order->order_modify_amount)?$order->order_modify_amount:$order->order_total_amount;?>&nbsp;<?php echo $currency;?></td>
	            <td><?php echo ($t_status)?$this->translator('order_tracking_status_'.$t_status, 'shop'):'-'?></td>
	            <td>
		            <?php if($t_status == 'finished'):?>
		            	<?php if(null != @$evaluation->seller_user_id):?>
							<a class="btnSellerFb" rel="<?php echo $order->order_id;?>" href="javascript:void(0);"><?php echo $this->translator('customer_view_evaluation_by_seller');?></a><br/>
						<?php else:?>
							<?php echo $this->translator('customer_no_evaluation_by_seller');?>
						<?php endif;?>
						
						<?php if(null != @$evaluation->buyer_user_id):?>
		            		<a class="btnBuyerFb" rel="<?php echo $order->order_id;?>" href="javascript:void(0);"><?php echo $this->translator('customer_view_evaluation_by_buyer');?></a>
		            	<?php else:?>
		            		<a class="btnBuyerWriteFb" rel="<?php echo $order->order_id;?>" href="javascript:void(0);">
		            			<?php echo $this->translator('customer_write_evaluation_by_buyer');?>
		            		</a>
		            	<?php endif;?>
		            <?php else:?>
		            	-
		            <?php endif;?>	
		            
	            	<!--popup content-->
	            	<div id="popupSellerFb_<?php echo $order->order_id;?>" style="display:none; text-align:left;">
	            		<?php echo "<b>".$this->translator('customer_evaluation_point_col') ."</b>: ". @$evaluation->seller_to_buyer_evaluation;?> <br>
	            		<?php echo "<b>".$this->translator('customer_view_evaluation_by_seller') . "</b>: " . @$evaluation->seller_to_buyer_feedback;?>
	            	</div>
	            	<div id="popupBuyerFb_<?php echo $order->order_id;?>" style="display:none; text-align:left;">
	            		<?php echo "<b>". $this->translator('customer_evaluation_point_col') ."</b>: ". @$evaluation->buyer_to_seller_evaluation;?> <br>
	            		<?php echo "<b>". $this->translator('customer_view_evaluation_by_buyer') . "</b>: " . @$evaluation->buyer_to_seller_feedback;?>
	            	</div> 
	            	<div id="popupBuyerWriteFb_<?php echo $order->order_id;?>" style="display:none; text-align:left;">
	            		<form action="<?php echo $this->url(array(), 'customer_customer_evaluation')?>" method="POST" id="sellerEvaluationForm">
							<input type="hidden" value="<?php echo (null != @$evaluation->seller_user_id)?true:false;?>" name="update" />
							<input type="hidden" value="<?php echo true;?>" name="bEvaluated" />
							<input type="hidden" value="<?php echo $order->order_id;?>" name="order_id" />
							<input type="hidden" value="<?php echo $this->user_enterprise;?>" name="enterprise_id" />
							<input type="hidden" value="<?php echo $this->user->user_id;?>" name="buyer_id" />
							<input type="hidden" value="<?php echo $order->enterprise_id;?>" name="eval_enterprise_id" />
							<input type="hidden" value="list_action" name="list_action" />
							<div style="float:left;">
								<label style="width:80px;"><b><?php echo $this->translator('order_view_point', 'shop');?></b>:</label>
								<select name="point" style="width:50px">
									<?php for($n=1;$n<=10;$n++):?>
									<option value="<?php echo $n;?>"><?php echo $n;?></option>
									<?php endfor;?>
								</select>
							</div>
							<div style="float:left;">
								<div class="evaluation_label" style="float:left;"><b><?php echo $this->translator('order_view_evaluation', 'shop');?></b>:</div>
								<div style="float:left;"><textarea name="evaluation" style="width:250px; height:70px"></textarea></div>
							</div>
							<div style="margin-top:3px; float:left;">
								<label style="width:80px;">&nbsp;</label>
								<button type="submit"><span style="height:30px; text-align:center; width:auto;" ><?php echo $this->translator('order_rating_save_button','shop');?></span></button>
							</div>
						</form>
	            	</div>
	            	<!--end popup content-->
	            </td>
	            <!-- Huy don hang -->
				<td>
					<a href="javascript:void(0);" rel="<?php echo $this->url(array('order_id'=>$order->order_id),"customer_cancel_order");?>" onclick='updateOrderStatus(this);'><?php echo $this->translator("customer_cancel_order");?></a>
				</td>
				<!--<td><input type="checkbox" <?php if(null != @$evaluation->buyer_user_id):?>checked<?php endif;?> disabled="true" /></td>
	            <td><input type="checkbox" <?php if(null != @$evaluation->seller_user_id):?>checked<?php endif;?> disabled="true" /></td>-->
	        </tr>
	        <?php endforeach;?>
	        <?php if($this->numOrder > $this->perPage):?>
	        <tr>
	        	<td colspan="6">
	        		<?php echo $this->paginator()->slide($this->paginator, $this->paginatorOptions);?>
	        	</td>
	        </tr>	   
	        <?php endif;?>     
	    </table>
	    <?php endif;?>
	    <?php endif;?>	 
	    
	    <!--Evaluation history-->
	    <?php if(!$this->isEnterprise || $this->isAllowAction):?>
	    <?php echo $this->widget('customer','evaluser',array('user_id'=>$this->user->user_id)); ?>
	    <?php endif;?>
	    <!--End evaluation history-->   
	</div>
    <!--End order list-->
    
    <!--customer info-->
    <div class="grid_3" style="width:250px; margin:0;">
    	<?php if($this->isAllowAction):?>
        <div class="grid_3 icon_title alpha" style="width:250px;">
        	<div style="float:left; width: 200px"><span><?php echo $this->translator('customer_info');?></span></div>        	
        	<?php if($this->isAllowAction):?>
        	<div style="float:right; width:50px; text-align:right; padding-top:8px;">
        		<a href="<?php echo $this->url(array('user_name' => $user->user_name),'customer_customer_edit');?>"><?php echo $this->translator('customer_edit_info');?></a>
        	</div>
        	<?php endif;?>
        </div>	    	    
	    <div class="grid_3" style="margin: 0; width: 250px;">
	        <div class="clearfix t_a_bottom">
	            <div class="box_account"> 	                
                	<div class="caption icon_title">	                    	
                    	<span style="font-size:10px;"><?php echo $this->translator('customer_billing_info');?></span>	                    	
                    </div>
	                <div class="grid_3">
	                    <label><?php echo $this->translator('customer_customer_name'); ?>:</label>
	                    <span><?php echo isset($user->full_name)?$user->full_name:'-';?></span>
	                </div>
	                
	                <div class="grid_3">
	                    <label><?php echo $this->translator('customer_user_name'); ?>:</label>
	                    <span><?php echo isset($user->user_name)?$user->user_name:'-';?></span>    
	                </div>
	                
	                <div class="grid_3">	                	
	                    <label><?php echo $this->translator('customer_customer_email'); ?>:</label>
	                    <span><?php echo isset($user->email)?$user->email:'-';?></span>
	                </div>
	                
	                <div class="grid_3">    	
	                    <label><?php echo $this->translator('customer_customer_address'); ?>:</label>
	                    <span><?php echo isset($customer->customer_address)?$customer->customer_address:'-';?></span>	                    
	                </div>
	                
	                <div class="grid_3">	                	
	                    <label><?php echo $this->translator('customer_customer_city'); ?>:</label>
	                    <span><?php echo isset($customer->customer_city)?$customer->customer_city:'-';?></span>	                    
	                </div>
	                <div class="grid_3">	                	
	                    <label><?php echo $this->translator('customer_customer_tel'); ?>:</label>
	                    <span><?php echo isset($customer->customer_tel)?$customer->customer_tel:'-';?></span>	                    
	                </div>
	                <?php if($this->isEnterprise):?>
	                <?php					
						$isEnterprise = $this->isEnterprise;
						$arrRoute = array(
                        	'enterprise_id' => $this->enterprise_info->id,
                        	'enterprise_name' => Tomato_Utility_String::removeSign($this->enterprise_info->company_name_en, '-', true),
                    	);
	                ?>
	                <div class="grid_3">	                	
	                    <label><?php echo $this->translator('customer_customer_enterprise_name'); ?>:</label>
	                    <span><a href="<?php echo $this->url($arrRoute, 'bizprofile_enterprise_index');?>"><?php echo $this->enterprise_info->company_name_en;?></a></span>	                    
	                </div>	                
	                <?php endif;?>
	            </div>	            
	            <div class="box_account">
	                <div class="caption icon_title">
	                	<span style="font-size:10px;"><?php echo $this->translator('customer_shipping_info');?></span>	                    	
	                </div>
	                <div class="grid_3">
	                    <label><?php echo $this->translator('customer_customer_name'); ?>:</label>
	                    <span><?php echo isset($customer->shipping_name)?$customer->shipping_name:'-';?></span>
	                </div>
	                <div class="grid_3">
	                    <label><?php echo $this->translator('customer_customer_email'); ?>:</label>
	                    <span><?php echo isset($customer->shipping_email)?$customer->shipping_email:'-';?></span>
	                </div>
	                <div class="grid_3">
	                    <label><?php echo $this->translator('customer_customer_address'); ?>:</label>
	                    <span><?php echo isset($customer->shipping_address)?$customer->shipping_address:'-';?></span>
	                </div>
	                <div class="grid_3">
	                    <label><?php echo $this->translator('customer_customer_city'); ?>:</label>
	                    <span><?php echo isset($customer->shipping_city)?$customer->shipping_city:'-';?></span>
	                </div>
	                <div class="grid_3">
	                    <label><?php echo $this->translator('customer_customer_tel'); ?>:</label>
	                    <span><?php echo isset($customer->shipping_tel)?$customer->shipping_tel:'-';?></span>
	                </div>
	            </div>
	        </div>
	    </div>
	    <?php else:?>
	    <div class="grid_3" style="margin: 0; width: 250px;">	        
	        <div class="clearfix t_a_bottom">
	            <div class="box_account">
	            	<div class="caption icon_title">	                    	
                    	<span style="font-size:10px;"><?php echo $this->translator('customer_info');?></span>	                    	
                    </div>
	                <div class="grid_3">	
	                    <label><?php echo $this->translator('customer_customer_name'); ?>:</label>
	                    <span><?php echo isset($user->full_name)?$user->full_name:'-';?></span>
	                </div>
	                <div class="grid_3">	
	                    <label><?php echo $this->translator('customer_customer_city'); ?>:</label>
	                    <span><?php echo isset($customer->customer_city)?$customer->customer_city:'-';?></span>
	                </div>
	                <?php if($this->isEnterprise):?>
	                <?php
	                    $arrRoute = array(
	                        'enterprise_id' => $this->enterprise_info->id,
	                        'enterprise_name' => Tomato_Utility_String::removeSign($this->enterprise_info->company_name_en, '-', true),
	                    );
	                ?>
	                <div class="grid_3">
	                    <label><?php echo $this->translator('customer_customer_enterprise'); ?>:</label>
	                    <span><a href="<?php echo $this->url($arrRoute,'bizprofile_enterprise_index');?>"><?php echo ($this->lang == 'vi_VN')?$this->enterprise_info->company_name_vn:$this->enterprise_info->company_name_en;?></a></span>
	                </div>
	                <?php endif;?>
	            </div>
	        </div>
	    </div>
	    <?php endif;?>
	</div>	
	<!--end customer info-->
</div>  

<div id="messageDialog"></div>
<div id="confirmDialog"></div>

<script type="text/javascript">
function updateOrderStatus(this_){
	var href = $(this_).attr("rel");
	$.ajax({
	   type: "GET",
	   url: href,
	   dataType: "json",
	   success: function(msg){		
		if(msg.success == true){
			alert("Hủy hóa đơn thành công");
		}else
			alert("Có lỗi trong quá trình hủy hóa đơn : "+ msg.msg);
	   }
	});
	return false;
}
$(document).ready(function() {
	
	
	var dialogOpts = {
        title: "<?php echo $this->translator('customer_view_evaluation_by_seller')?>",
        modal: true,
        autoOpen: false,
        height: 250,
        width: 400,
        show: 'slide'        
    };

    //Feed back from Seller
    $('.btnSellerFb').click(function() {
        self = this;
        rel = $(self).attr('rel');
        
        $('#popupSellerFb_'+rel).dialog(dialogOpts);
        $('#popupSellerFb_'+rel).dialog('option', 'title', '<?php echo $this->translator('customer_view_evaluation_by_seller')?>');
        $('#popupSellerFb_'+rel).dialog('open');
    });

    //Feed back from Buyer
    $('.btnBuyerFb').click(function() {
        self = this;
        rel = $(self).attr('rel');
        
        $('#popupBuyerFb_'+rel).dialog(dialogOpts);
        $('#popupBuyerFb_'+rel).dialog('option', 'title', '<?php echo $this->translator('customer_view_evaluation_by_buyer')?>');
        $('#popupBuyerFb_'+rel).dialog('open');
    });

  //Buyer wirte Feed back
    $('.btnBuyerWriteFb').click(function() {
        self = this;
        rel = $(self).attr('rel');
        
        $('#popupBuyerWriteFb_'+rel).dialog(dialogOpts);
        $('#popupBuyerWriteFb_'+rel).dialog('option', 'title', '<?php echo $this->translator('customer_write_evaluation_by_buyer')?>');
        $('#popupBuyerWriteFb_'+rel).dialog('open');
    });
});
</script>
<?php endif;?>